package sk.xorty.web;

import sk.xorty.domain.Person;
import sk.xorty.service.EmailSender;
import sk.xorty.service.PersonLister;

import javax.inject.Inject;

// fake controller
public class PersonController {

    @Inject
    PersonLister personLister;

    @Inject
    EmailSender emailSender;

    public String get(Model model) {
        model.put("people", personLister.list());

        return "people.jsp";
    }

    public String post(Person person) {
        System.out.println("adding person: " + person);

        // notify admin about adding new user
        emailSender.send(person.getName(), "admin@thisfakesystem.sk");

        return "redirect:people.jsp";
    }

}
